//
//  ADJgSDKSplashCustomEvent.m
//  AnyThinkSDKDemo
//
//  Created by 刘娟 on 2024/9/25.
//  Copyright © 2024 抽筋的灯. All rights reserved.
//

#import "ADJgSDKSplashCustomEvent.h"

@interface ADJgSDKSplashCustomEvent()

@end

@implementation ADJgSDKSplashCustomEvent
- (void)loadAdWithPosId:(NSString *)posId bottomView:(UIView *)bottomView{
    self.splashAdContainer = [[ADJgSDKSplashAdContainer alloc] initPosId:posId delegate:self];
    [self.splashAdContainer loadAdWithBottomView:bottomView];
}
- (void)showAdWithWindow:(UIWindow *)window{
    [self.splashAdContainer showAdInWindow:window];
}
// MARK: - Method
- (void)loadAndShowPosId:(NSString *)posId window:(UIWindow *)window withBottomView:(nullable UIView *)bottomView{
    self.splashAdContainer = [[ADJgSDKSplashAdContainer alloc] initPosId:posId delegate:self];
    [self.splashAdContainer loadAndShowInWindow:window withBottomView:bottomView];
}


// MARK: - ADJgSDKSplashAdDelegate
/**
 开屏加载成功
 
 @param splashAd 广告实例
 */
- (void)adjg_splashAdSuccessToLoadAd:(ADJgSDKSplashAd *)splashAd{
    if([[NSDate date] timeIntervalSinceDate:_expireDate] > 0){
//        NSError *error = [NSError errorWithDomain:ATADLoadingErrorDomain code:ATADLoadingErrorCodeADOfferLoadingFailed userInfo:@{NSLocalizedDescriptionKey:@"AT has failed to load splash.", NSLocalizedFailureReasonErrorKey:@"It took too long for ADJgSDK to load splash."}];
                [_splashAdContainer close];
                [self trackSplashAdLoadFailed:nil];
    }else{
            [self trackSplashAdLoaded:self.splashAdContainer];
    }
}

/**
 开屏展现成功
 
 @param splashAd 广告实例
 */
- (void)adjg_splashAdSuccessToPresentScreen:(ADJgSDKSplashAd *)splashAd{
    [self trackSplashAdShow];
}

/**
 开屏展现失败
 
 @param splashAd 广告实例
 @param error 具体错误信息
 */
- (void)adjg_splashAdFailToPresentScreen:(ADJgSDKSplashAd *)splashAd failToPresentScreen:(ADJgAdapterErrorDefine *)error{
    [_splashAdContainer close];
    [self trackSplashAdLoadFailed:nil];
    [self trackSplashAdShowFailed:nil];
}

/**
 开屏广告点击
 
 @param splashAd 广告实例
 */
- (void)adjg_splashAdClicked:(ADJgSDKSplashAd *)splashAd{
    [self trackSplashAdClick];
}

/**
 开屏被跳过
 
 @param splashAd 广告实例
 */
- (void)adjg_splashAdSkip:(ADJgSDKSplashAd *)splashAd{
}

/**
 开屏被关闭
 
 @param splashAd 广告实例
 */
- (void)adjg_splashAdClosed:(ADJgSDKSplashAd *)splashAd{
    [_splashAdContainer close];
    [self trackSplashAdClosed:nil];
}

/**
 开屏展示
 
 @param splashAd 广告实例
 */
- (void)adjg_splashAdEffective:(ADJgSDKSplashAd *)splashAd{
    
}

/**
 开屏关闭落地页
 
 @param splashAd 广告实例
 */
- (void)adjg_splashAdCloseLandingPage:(ADJgSDKSplashAd *)splashAd{
    [_splashAdContainer close];
    [self trackSplashAdClosed:nil];
}

- (NSString *)networkUnitId {
    return self.serverInfo[@"slot_id"];
}

@end
